$(function(){
	//列表下拉
	$('#table_menu').on('click','img[nc_type="flex"]',function(){
		var status = $(this).attr('status');
		if(status == 'open'){
			var pr = $(this).parent('td').parent('tr');
			var id = $(this).attr('fieldid');
			var obj = $(this);
			$(this).attr('status','none');
			$.ajax({
				url: web_site+'/Node/getNode/pid/'+id+'.html',
				type: "post",
				dataType: 'json',
				success: function(data){
					var src='';
					for(var i = 0;i < data.length;i++){
						src += '<tr class="text-c row'+id+'">';
						src += '<td>';
						if(data[i]['c_count'] > 0){
							src += '<img fieldid="'+data[i]['node_id']+'" status="open" nc_type="flex" src="'+static_url+'/images/admin/tv-expandable.gif">';
						}
						src += '</td>';
						src += '<td class="text-l">';
						var level = data[i]['level'];
						for(j = 2;j < level;j++){
							src += '&nbsp;&nbsp;&nbsp;&nbsp;';
						}
						if(data[i]['c_count'] > 0){
							src += '<img src="'+static_url+'/images/admin/tv-item1.gif">';
						}else{
							src += '<img src="'+static_url+'/images/admin/tv-expandable1.gif">';
						}
						src += data[i]['node_title']+'</td>';
						src += '<td class="text-c">'+data[i]['node_controll']+'</td>';
						src += '<td class="text-c">'+data[i]['node_action']+'</td>';
						src += '<td>';
						if(data[i]['is_menu'] == 1){
							src += '<span class="label label-success radius">菜单</span>';
						}else if(data[i]['is_menu'] == 0){
							src += '<span class="label label-danger radius">节点</span>';
						}
						src += '</td>';
						src += '<td>';
						if(data[i]['status'] == 1){
							src += '<span class="label label-success radius">显示</span>';
						}else if(data[i]['status'] == 0){
							src += '<span class="label label-error radius">隐藏</span>';
						}
						src += '</td>';
						src += '<td>'+data[i]['sort']+'</td>';
						src += '<td class="f-14 td-manage">'
						src += '<a style="text-decoration:none" class="ml-5" onclick="layer_open(\'编辑后台菜单\',\''+web_site+'/Node/edit/node_id/'+data[i]['node_id']+'\')" href="javascript:;" title="编辑"><i class="Hui-iconfont">&#xe6df;</i></a> ' 
						src += '<a style="text-decoration:none" class="ml-5" onClick="table_del(this,'+data[i]['node_id']+')" href="javascript:;" title="删除"><i class="Hui-iconfont">&#xe6e2;</i></a>'
						src += '</td>'
						src += '</tr>';
					}
					//插入
					pr.after(src);
					obj.attr('status','close');
					obj.attr('src',obj.attr('src').replace("tv-expandable","tv-collapsable"));
				},
				/*error: function(){
					alert('获取信息失败');
				}*/
				error: function (XMLHttpRequest, textStatus, errorThrown) {
					alert(XMLHttpRequest.status);
	                alert(XMLHttpRequest.readyState);
	                alert(XMLHttpRequest.responseText);
				}
			});
		}
		if(status == 'close'){
			$(".row"+$(this).attr('fieldid')).remove();
			$(this).attr('src',$(this).attr('src').replace("tv-collapsable","tv-expandable"));
			$(this).attr('status','open');
		}
	});
	
});